﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using Dao;
using Utils;

namespace ZiChengCode
{
    public partial class FrmMain : Form
    {
        AutoSizeFormClass asc = new AutoSizeFormClass();
        BaseBO bo = new BaseBO();
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            asc.controllInitializeSize(this);
            TreeNode nodetop = new TreeNode();
            nodetop.Text = "数据库连接";
            // tvServerList.Nodes.Add(nodetop);
            TreeNode node;
            BaseBO bo = new BaseBO();
            foreach (var tableModel in bo.GetTable())
            {
                node = new TreeNode(tableModel.TableName);
                node.Name = "table";
                nodetop.Nodes.Add(node);
            }
            tvServerList.AfterSelect += new TreeViewEventHandler(tvServerList_AfterSelect);
            tvServerList.Nodes.Add(nodetop);
        }

        void tvServerList_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //throw new NotImplementedException();
            if (tvServerList.SelectedNode != null && tvServerList.SelectedNode.Name == "table")
            {
                bo.TableName = tvServerList.SelectedNode.Text;
                //MessageBox.Show(tvServerList.SelectedNode.Text);
            }
        }

        private void FrmMain_SizeChanged(object sender, EventArgs e)
        {
            asc.controlAutoSize(this);
        }

        private void btnMakeCode_Click(object sender, EventArgs e)
        {
            btnMakeCode.Enabled = false;
            MakeCodeFactory.MakeCode(bo);
            btnMakeCode.Enabled = true;
        }

        private void nvsMakeSet_Click(object sender, EventArgs e)
        {

        }

        private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

    }
}
